package com.example.studentportrait.config;



import com.example.studentportrait.domain.dto.LoginUser;
import com.example.studentportrait.domain.entity.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import com.example.studentportrait.mapper.UserMapper;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class UserDetailsManger implements UserDetailsService {
    @Resource
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        //根据用户名查询用户信息
        User user = userMapper.selectByAccount(account);
//如果查询不到数据就通过抛出异常来给出提示
        if(Objects.isNull(user)){
            throw new RuntimeException("用户名错误");
        }
//TODO 根据用户查询权限信息 添加到LoginUser中
        List<String> list =null;
//封装成UserDetails对象返回
        return new LoginUser(user,list);
    }
}

